var string DF_Funcs_s[11];
var int    DF_Funcs_i[11];

/* Eigene Variablen */
instance focusBar(oCViewStatusBar);
instance hpBar(oCViewStatusBar);

/* Eigene Funktion (Jede Sekunde aufgerufen) */
func void DF_AddLoopFuncs() {
	PrintDebug("BOTK: CONSTLOOP: Start");
	
	if(!Npc_IsInState(hero, ZS_Talk)) {
		MEM_AssignInst(focusBar, MEM_Game.focusBar);
		MEM_AssignInst(hpBar, MEM_Game.hpBar);
		hpBar.zCView_vsizex = focusBar.zCView_vsizex*4;
		hpBar.zCView_vposX = focusBar.zCView_vposX-(focusBar.zCView_vsizex*3/2);
	};	
	//if(B_SCRPT==3) { MEM_CallByString("B_SKRIPT_SCHLEIFE"   ); };
	//if(B_SCRPT==4) { MEM_CallByString("B_SKRIPT_SCHLEIFE_S1"); B_SCRPT = 0; };
	
	PrintDebug("BOTK: CONSTLOOP: Finished");
};

//--------------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------------
func string _DF_PushArr_S() {
    return DF_Funcs_s;
};
func string _DF_GetFuncsArr_S(var int offs) {
    if(offs > 10) {
        PrintDebug("WAR: Funcs Overflow!");
        return "";
    };
    _DF_PushArr_S();
    MEMINT_StackPopInst();
    MEMINT_StackPushInst(zPAR_TOK_PUSHINT);
    var int adr; adr = MEMINT_StackPopInt();
    adr += 20*offs;
    return MEM_ReadString(adr);
};
func void _DF_SetFuncsArr_S(var int offs, var string fnc) {
    if(offs > 10) {
        PrintDebug("WAR: Funcs Overflow!");
        return;
    };
    _DF_PushArr_S();
    MEMINT_StackPopInst();
    MEMINT_StackPushInst(zPAR_TOK_PUSHINT);
    var int adr; adr = MEMINT_StackPopInt();
    adr += 20*offs;
    MEM_WriteString(adr, fnc);
};
//--------------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------------
func int _DF_PushArr_I() {
    return DF_Funcs_i;
};
func int _DF_GetFuncsArr_I(var int offs) {
    if(offs > 10) {
        PrintDebug("WAR: Funcs Overflow!");
        return 0;
    };
    _DF_PushArr_I();
    MEMINT_StackPopInst();
    MEMINT_StackPushInst(zPAR_TOK_PUSHINT);
    var int adr; adr = MEMINT_StackPopInt();
    adr += 4*offs;
    return MEM_ReadInt(adr);
};
func void _DF_SetFuncsArr_I(var int offs, var int fnc) {
    if(offs > 10) {
        PrintDebug("WAR: Funcs Overflow!");
        return;
    };
    _DF_PushArr_I();
    MEMINT_StackPopInst();
    MEMINT_StackPushInst(zPAR_TOK_PUSHINT);
    var int adr; adr = MEMINT_StackPopInt();
    adr += 4*offs;
    MEM_WriteInt(adr, fnc);
};
//--------------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------------
func int _DF_SearchFirstEmpty() {
    var int offs; offs = 0;
    var int pos;
	pos = MEM_StackPos.position;
        if(!_DF_GetFuncsArr_I(offs)) { printdebug(cs2("DF NextFuncOffset: ", intTostring(offs))); return offs; };
        offs+=1;
    MEM_StackPos.Position = pos;
};
func void DF_AddFunc(var string fnc, var int delay) {
    MEM_InitLabels();
    MEM_InitGlobalInst();
    var int offs; offs = _DF_SearchFirstEmpty();
    _DF_SetFuncsArr_I(offs, delay);
    _DF_SetFuncsArr_S(offs, fnc);
};
func void DF_LoopFunc() {
	//PrintDebug("BOTK: DFLOOP: Start");

    DF_AddLoopFuncs();
    var int pos;
    var int sav; sav = 0;
    var int offs; offs = 0;
    sav = 0;
    offs = 0;
    pos = MEM_StackPos.position;
        sav = _DF_GetFuncsArr_I(offs);
        if(sav) {
            sav -= 1;
            _DF_SetFuncsArr_I(offs,sav);
			var string x; var string y;
			x = IntToString(sav);
			y = IntToString(offs);
            if(!sav) {
				MEM_CallByString(_DF_GetFuncsArr_S(offs));
			};
        };
        offs+=1;
        if(offs<11) {
    MEM_StackPos.Position = pos; };
	//Wld_SendTrigger("DF");
	
	//PrintDebug("BOTK: DFLOOP: Finished");
};
func void DF_LoopFunc2() {
	PrintDebug("BOTK: DFLOOP (2): Start");
	
    var int pos;
    var int sav; sav = 0;
    var int offs; offs = 0;
    sav = 0;
    offs = 0;
    pos = MEM_StackPos.position;
        sav = _DF_GetFuncsArr_I(offs);
        if(sav) {
            sav -= 1;
            _DF_SetFuncsArr_I(offs,sav);
			var string x; var string y;
			x = IntToString(sav);
			y = IntToString(offs);
            if(!sav) {
				MEM_CallByString(_DF_GetFuncsArr_S(offs));
			};
        };
        offs+=1;
        if(offs<11) {
    MEM_StackPos.Position = pos; };
	
	PrintDebug("BOTK: DFLOOP (2): Finished");
};
